home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / pct1-b.zip / APP2.DOC < prev    next >
Text File  |  1990-08-02  |  31KB  |  887 lines

  1.  
  2.  
  3.  
  4.                                                                           xiii
  5.  
  6.                            THE 8086 INSTRUCTION SET
  7.  
  8.  
  9.              Before I go through the instructions I need to say something
  10.              about the structure of the instructions. For the majority of
  11.              instructions, two bits in the first instruction byte and the
  12.              whole second byte determine whether it is a byte or word
  13.              instruction and whether it is:
  14.  
  15.                  1. register, register
  16.                  2. register, memory
  17.                  3. memory, register
  18.  
  19.              These refer to the 8 arithmetic registers, not the segment
  20.              registers. "Memory" is any allowable addressing mode. Therefore,
  21.              it is simpler to abbreviate this as:
  22.  
  23.                  reg/mem, reg/mem
  24.  
  25.              This will always mean:
  26.  
  27.                  1. either a byte or word operation is allowed
  28.                  2. any of the above 3 possibilities is allowed
  29.  
  30.              unless specifically stated otherwise. Another possibility is the
  31.              operations with constants:
  32.  
  33.                  add  ax, 7
  34.                  xor  sign_flag, 80h
  35.  
  36.              These follow the same form. There are two possibilities:
  37.  
  38.                  1. register, constant
  39.                  2. memory, constant
  40.  
  41.              where this may be a byte or a word, "register" is any arithmetic
  42.              register, and "memory" is any allowable addressing mode. These
  43.              will be abbreviated:
  44.  
  45.                  reg/mem, constant
  46.  
  47.              If we are taliking about a segment register, they will be
  48.              abbreviated:
  49.  
  50.                  segreg
  51.  
  52.              If anything does not follow this pattern, it will be explicitly
  53.              stated.
  54.  
  55.  
  56.              DESTINATION,SOURCE
  57.  
  58.              The standard way of writing instructions is with the destination
  59.              on the left and the source on the right:
  60.  
  61.              ______________________
  62.  
  63.              The PC Assembler Tutor - Copyright (C) 1989 Chuck Nelson
  64.  
  65.  
  66.  
  67.  
  68.              The PC Assembler Tutor                                        xiv
  69.              ______________________
  70.  
  71.  
  72.                  add  destination, source
  73.  
  74.              The register or memory location on the left ALWAYS gets the
  75.              result of the operation. The thing on the right is the second
  76.              operand (if any).
  77.  
  78.              ADDRESSING MODES
  79.  
  80.              These are the natural (default) segments of all addressing modes:
  81.  
  82.                  (1) DS
  83.  
  84.                       variable + (constant)
  85.                       [bx] + (constant)
  86.                       [si] + (constant)
  87.                       [di] + (constant)
  88.                       [bx+si] + (constant)
  89.                       [bx+di] + (constant)
  90.  
  91.  
  92.                  (2) SS
  93.  
  94.                       [bp] + (constant)
  95.                       [bp+si] + (constant)
  96.                       [bp+di] + (constant)
  97.  
  98.              Where the constant is optional. Segment overrides may be used.
  99.              The segment overrides are:
  100.  
  101.                  SEGMENT OVERRIDE         MACHINE CODE (hex)
  102.                       CS:                      2E
  103.                       DS:                      3E
  104.                       ES:                      26
  105.                       SS:                      36
  106.  
  107.  
  108.              These default segments apply to all instructions except the
  109.              string instructions, which will be explained individually.
  110.  
  111.  
  112.  
  113.              THE INSTRUCTION SET
  114.  
  115.              AAA  (ascii adjust for addition) adjusts AL, assuming that it
  116.              contains the result of a legitimate unpacked BCD addition. If the
  117.              lower half-byte has generated a result 10 or over, it subtracts
  118.              10, carries 1 to AH, and sets the carry flag. If the result is 9
  119.              or less, it clears CF. In either case it zeroes the upper
  120.              half-byte of AL.
  121.  
  122.  
  123.              AAD (ascii adjust for division) PREPARES AL and AH for division.
  124.              It assumes that AH contains the 10's digit and AL contains the
  125.              1's digit of a two byte unpacked BCD number. It multiplies AH by
  126.              10 and adds it to AL, thus making a single integer between 0 and
  127.              99. It zeroes AH in preparation for unsigned division.
  128.  
  129.  
  130.  
  131.  
  132.              Appendix II - The 8086 Instruction Set                         xv
  133.              ______________________________________
  134.  
  135.  
  136.  
  137.              AAM (ascii adjust for multiplication) adjusts AL, assuming that
  138.              it contains the result of a legitimate BCD multiplication. It
  139.              divides the result by 10, putting the quotient in AH and the
  140.              remainder in AL. If AL contains 73 before AAM, then afterwards AH
  141.              will contain 7 and AL will contain 3
  142.  
  143.  
  144.              AAS  (ascii adjust for subtraction) adjusts AL, assuming that it
  145.              contains the result of a legitimate unpacked BCD subtraction. If
  146.              the lower half-byte has generated a result -1 or less, it borrows
  147.              1 from AH, adds 10 to AL, and sets the carry flag. If the result
  148.              is 0 or more, it clears CF. In either case it zeroes the upper
  149.              half-byte of AL.
  150.  
  151.  
  152.              ADC (add with carry) adds two integers, either signed or
  153.              unsigned, and adds in the carry from the previous arithmetic
  154.              operation. It is used for multiple word (byte) addition.
  155.  
  156.                  adc  reg/mem, reg/mem
  157.                  adc  reg/mem, constant
  158.  
  159.  
  160.              ADD adds two integers, either signed or unsigned.
  161.  
  162.                  add  reg/mem, reg/mem
  163.                  add  reg/mem, constant
  164.  
  165.  
  166.              AND ands two bytes or words. A bit remains set only if both its
  167.              respective source and destination bits were set.
  168.  
  169.                  and  reg/mem, reg/mem
  170.                  and  reg/mem, constant
  171.  
  172.  
  173.  
  174.              CALL calls a procedure. The two forms we have used are NEAR and
  175.              FAR calls.
  176.  
  177.                  call set_regs
  178.                  call FAR PTR calculate_array
  179.  
  180.              There are two other forms where the addresses of the subprograms
  181.              are in memory and changable. You should only use these forms if
  182.              you are writing an operating system or a compiler, since they are
  183.              an invitation to disaster.
  184.  
  185.  
  186.  
  187.              CBW sign extends the signed byte in AL to AH:AL in preparation
  188.              for signed division. It is used alone without any register
  189.              specification.
  190.  
  191.                  cbw
  192.  
  193.  
  194.  
  195.  
  196.              The PC Assembler Tutor                                        xvi
  197.              ______________________
  198.  
  199.  
  200.  
  201.  
  202.              CLC clears the carry flag (CF = 0).
  203.  
  204.  
  205.              CLD clears the direction flag (increments string pointers).
  206.  
  207.  
  208.              CLI clears the interrupt flag (disables interrupts). All maskable
  209.              interrupts must wait till the flag is set again before they will
  210.              be processed.
  211.  
  212.  
  213.              CMC changes the value of the carry flag. If CF =1, then CF = 0;
  214.              if CF = 0, then CF = 1.
  215.  
  216.  
  217.              CMP compares two values. It is the same as SUB except it does not
  218.              alter the "destination" variable. Its job is to set the flags as
  219.              if a subtraction had been performed, in preparation for a
  220.              conditional jump instruction.
  221.  
  222.                  cmp  reg/mem, reg/mem
  223.                  cmp  reg/mem, constant
  224.  
  225.  
  226.  
  227.              CMPS compares the byte (or word) at DS:[si] with the one at
  228.              ES:[di], (calculating [si] - [di]) and sets the flags
  229.              accordingly. It increments (or decrements) SI and DI depending on
  230.              the setting of DF, the direction flag (by 1 for bytes and by 2
  231.              for words). You may use CS:[si], SS:[si] or ES:[si], but you MAY
  232.              NOT OVERRIDE ES:[di]. Notice that SI and DI are reversed from
  233.              their position in the other string instructions.
  234.  
  235.                  cmpsb
  236.                  cmpsw
  237.                  cmps BYTE PTR SS:[si], ES:[di]     ;or CS, DS, ES:[si]
  238.                  cmps WORD PTR SS:[si], ES:[di]     ;or CS, DS, ES:[si]
  239.  
  240.  
  241.  
  242.              CWD sign extends the signed integer in AX to DX:AX in preparation
  243.              for signed word division. No register specification is used.
  244.  
  245.                  cwd
  246.  
  247.  
  248.  
  249.              DAA (decimal adjust for addition) adjusts AL, assuming that it
  250.              contains the result of a legitimate packed BCD addition. It
  251.              treats AL as two independent half-bytes. If the result of the
  252.              lower half-byte is 10 or over, it subtracts 10 from the lower
  253.              half-byte and adds the carry to the upper half byte. It then
  254.              looks at the upper half byte. If its result is 10 or over, DAA
  255.              subtracts 10 from the upper half byte and sets the carry flag.
  256.  
  257.  
  258.  
  259.  
  260.              Appendix II - The 8086 Instruction Set                       xvii
  261.              ______________________________________
  262.  
  263.              Otherwise the carry flag is cleared.
  264.  
  265.  
  266.  
  267.              DAS (decimal adjust for subtraction) adjusts AL, assuming that it
  268.              contains the result of a legitimate packed BCD subtraction.It
  269.              treats AL as two independent half-bytes. If the result of the
  270.              lower half-byte is -1 or less, it adds 10 to the lower half-byte
  271.              and borrows 1 from the upper half byte. It then looks at the
  272.              upper half byte. If its result is -1 or less, DAA adds 10 to the
  273.              upper half byte and sets the carry flag to indicate a borrow.
  274.              Otherwise the carry flag is cleared.
  275.  
  276.  
  277.  
  278.              DEC decrements the byte or word by 1. It does not alter CF.
  279.  
  280.                  dec  reg/mem
  281.  
  282.  
  283.  
  284.              DIV performs unsigned division. If byte division, the unsigned
  285.              double byte must be in AH:AL. Afterwards, AL has the quotient and
  286.              AH has the remainder. If word division, the unsigned word must be
  287.              in DX:AX. Afterwards, AX has the quotient, and DX the remainder.
  288.              Division by a constant is not allowed. The DIV instruction does
  289.              not mention DX:AX or AH:AL. They are understood.
  290.  
  291.                  div  reg/mem
  292.  
  293.  
  294.  
  295.              ESC (escape) signals to the 8086 that the bytes starting with the
  296.              ESC byte are a coprocessor instruction. The 8086 will calculate a
  297.              memory address (if appropriate) and give it to the coprocessor.
  298.              The 8086 will then go on to the next instruction.  
  299.  
  300.  
  301.  
  302.              HLT (halt) halts the machine. It can be restarted with a reset, a
  303.              non-maskable interrupt, or (if IEF is set) with a maskable
  304.              interrupt.
  305.  
  306.  
  307.  
  308.              IDIV performs signed integer division. For byte division, the
  309.              value in AL must be sign extended to AH (with CBW), giving the
  310.              double signed byte AH:AL, after division, AL contains the
  311.              quotient and AH contains the remainder. For word division, the
  312.              value in AX must be sign extended to DX (with CWD), giving the
  313.              double signed word DX:AX, after division, AX contains the
  314.              quotient and DX contains the remainder. Division by a constant is
  315.              not allowed. IDIV cannot perform multiple word division. To do
  316.              that, you need to make the numbers positive and use DIV,
  317.              adjusting the signs afterwards. IDIV does not mention the AL or
  318.              AX register, it is understood.
  319.  
  320.  
  321.  
  322.  
  323.  
  324.              The PC Assembler Tutor                                      xviii
  325.              ______________________
  326.  
  327.                  idiv reg/mem
  328.  
  329.  
  330.  
  331.              IMUL performs signed integer multiplication. The multiplicand
  332.              must be in AX (or AL for bytes). After the multiplication, the
  333.              result is in DX:AX for words and AH:AL for bytes. If DX (or AH
  334.              for bytes) contains significant information, then CF is set (=1).
  335.              If all the information is in AX (or AL for bytes) then CF = 0.
  336.              Multiplication by a constant is not allowed. The IMUL instruction
  337.              does not mention AX (or AL); it is understood.
  338.  
  339.                  imul mem/reg
  340.  
  341.  
  342.  
  343.              IN allows you to move data from a port address to AX (for a word)
  344.              or AL (for a byte). There are two forms:
  345.  
  346.                  IN   al, port_number
  347.                  IN   al, dx
  348.  
  349.              Where 'port_number' is a CONSTANT that is hard coded into the
  350.              machine instruction and is from 0 - 255. The port address in DX
  351.              may be from 0-65535. It must be the DX register.
  352.  
  353.  
  354.  
  355.              INC increments a register or a variable by 1. It does not effect
  356.              CF. 
  357.                  inc  reg/mem
  358.  
  359.  
  360.  
  361.              INT (interrupt) sends the program to a subprogram whose address
  362.              is located in the interrupt vector table in low memory. For any
  363.              interrupt number I, the 8086 goes to segment 0000, offset
  364.              (I X 4). It loads IP with the first two bytes, then loads CS from
  365.              the next two bytes. The next instruction executed will be at the
  366.              new CS:IP. Before loading the new CS and IP, it pushes (1) the
  367.              flags, (2) the old CS and (3) the old IP in that order.
  368.  
  369.                  int  3
  370.                  int  21h
  371.  
  372.  
  373.  
  374.              INTO checks OF. If OF = 1, INTO generates interrupt 4. Otherwise
  375.              it does nothing. It is used for error handling of signed numbers.
  376.  
  377.                  into
  378.  
  379.  
  380.  
  381.              IRET (interrupt return) is a special return instruction for
  382.              interrupt routines. It pops (1) the old IP, (2) the old CS, and
  383.              (3) the old flags in that order.
  384.  
  385.  
  386.  
  387.  
  388.              Appendix II - The 8086 Instruction Set                        xix
  389.              ______________________________________
  390.  
  391.  
  392.                  iret
  393.  
  394.  
  395.  
  396.              JUMPS ---------------------------------------------------------
  397.  
  398.              There are two kinds of jumps. JMP is unconditional and can jump
  399.              anywhere in the segment. All other jumps are conditional and are
  400.              limited jumps from -128 to +127 bytes from the END of the jump
  401.              instruction.{1}
  402.  
  403.  
  404.              THESE ARE THE JUMP INSTRUCTIONS FOR SIGNED NUMBERS
  405.  
  406.                  jg        ; jump if greater
  407.                  jnle      ; jump if not (less or equal) 
  408.  
  409.                  jl        ; jump if less
  410.                  jnge      ; jump if not (greater or equal) 
  411.  
  412.                  je        ; jump if equal
  413.                  jz        ; jump if zero 
  414.  
  415.                  jge       ; jump if greater or equal
  416.                  jnl       ; jump if not less
  417.  
  418.                  jle       ; jump if less or equal
  419.                  jng       ; jump if not greater
  420.  
  421.                  jne       ; jump if not equal
  422.                  jnz       ; jump if not zero 
  423.  
  424.  
  425.  
  426.              THESE ARE THE JUMP INSTRUCTIONS FOR UNSIGNED NUMBERS
  427.  
  428.                  ja        ; jump if above
  429.                  jnbe      ; jump if not (below or equal) 
  430.  
  431.                  jb        ; jump if below
  432.                  jnae      ; jump if not (above or equal) 
  433.  
  434.                  je        ; jump if equal
  435.                  jz        ; jump if zero 
  436.  
  437.                  jae       ; jump if above or equal
  438.                  jnb       ; jump if not below 
  439.  
  440.                  jbe       ; jump if below or equal
  441.                  jna       ; jump if not above
  442.              ____________________
  443.  
  444.                 1 There is also a long jump which can jump anywhere in memory
  445.              (from 00000 to FFFFF). Except under special circumstances, using
  446.              this is truly lousy programming practice. The long jump is for
  447.              the Olympics, not for quality programming. 
  448.  
  449.  
  450.  
  451.  
  452.              The PC Assembler Tutor                                         xx
  453.              ______________________
  454.  
  455.  
  456.                  jne       ; jump if not equal
  457.                  jnz       ; jump if not zero 
  458.  
  459.  
  460.              THESE JUMPS CHECK A SINGLE FLAG 
  461.  
  462.              These come in opposite pairs
  463.  
  464.                  jc        ; jump if the carry flag is set
  465.                  jnc       ; jump if the carry flag is not set
  466.  
  467.                  jo        ; jump if the overflow flag is set
  468.                  jno       ; jump if the overflow flag is not set
  469.  
  470.                  jp or jpe ; jump if parity flag is set (parity is even)
  471.                  jnp or jpo  ;jump if parity flag is not set (parity is odd)
  472.  
  473.  
  474.                  js        ; jump if the sign flag is set (negative )
  475.                  jns       ; jump if the sign flag is not set (positive or 0)
  476.  
  477.  
  478.              THIS CHECKS THE CX REGISTER
  479.  
  480.                  jcxz      ; jump if cx is zero
  481.  
  482.              This is used before entry to a loop to make sure the loop counter
  483.              is not set to 0.
  484.  
  485.  
  486.              INDIRECT JUMPS are jumps where the information for the jump is
  487.              stored in memory (or in a register for an in-segment jump). These
  488.              forms are dangerous and should be used only when writing things
  489.              like multi-tasking operating systems. Have you written one
  490.              lately?
  491.  
  492.              END OF JUMPS  - - - - - - - - - - - - - - - - - - - - - - -
  493.  
  494.  
  495.              LAHF (load AH from flags) loads the lower half of the flags
  496.              register into AH.
  497.  
  498.  
  499.  
  500.              LDS (load DS) loads the first two bytes of the memory address
  501.              into the named arithmetic register and the next two bytes into
  502.              DS. The register may be any arithmetic register, but this is
  503.              designed for the 4 addressing registers: BX, SI, DI and BP.
  504.  
  505.                       lds  reg, memory_address
  506.  
  507.  
  508.  
  509.              LEA calculates an offset address and puts it in the named
  510.              register.
  511.  
  512.  
  513.  
  514.  
  515.  
  516.              Appendix II - The 8086 Instruction Set                        xxi
  517.              ______________________________________
  518.  
  519.                       lea  ax, [bp+si]+145
  520.  
  521.  
  522.  
  523.              LES (load ES) loads the first two bytes into the named arithmetic
  524.              register and the next two bytes into ES. The register may be any
  525.              arithmetic register, but this is designed for the 4 addressing
  526.              registers: BX, SI, DI and BP.
  527.  
  528.                       les  reg, memory_address
  529.  
  530.  
  531.  
  532.              LOCK is for use if there is more than one 8086 operating in a
  533.              computer. LOCK allows one 8086 to be the only one which can read
  534.              from or write to memory during the following instruction. 
  535.  
  536.  
  537.  
  538.              LODS moves a byte or word from DS:[si] to AL or AX, and
  539.              increments (or decrements) SI depending on the setting of DF, the
  540.              direction flag (by 1 for bytes and by 2 for words). You may use
  541.              CS:[si], SS:[si] or ES:[si].
  542.  
  543.                  lodsb
  544.                  lodsw
  545.                  lods BYTE PTR SS:[si]         ; or CS, DS, ES:[si]
  546.                  lods WORD PTR SS:[si]         ; or CS, DS, ES:[si]
  547.  
  548.  
  549.  
  550.              LOOP/LOOPE/LOOPNE are conditional jumps (-128 to + 127 bytes).
  551.              They will jump back to the start of the loop (which is identified
  552.              by a label), under the following conditions:
  553.  
  554.                  loop      decrement cx ; jump back if cx is not zero
  555.                  loope     decrement cx ; jump back if cx not zero AND zf = 1
  556.                  loopz     decrement cx ; jump back if cx not zero AND zf = 1
  557.                  loopne    decrement cx ; jump back if cx not zero AND zf = 0
  558.                  loopnz    decrement cx ; jump back if cx not zero AND zf = 0
  559.  
  560.              Here, 'e' stands for equal, 'z' is zero and 'n' is not.
  561.  
  562.                  loop some_label
  563.  
  564.  
  565.  
  566.              MOV is the general instruction for moving bytes or words on the
  567.              8086. The forms are:
  568.  
  569.                  reg/mem, reg/mem
  570.                  reg/mem, constant
  571.                  segreg, reg/mem
  572.                  reg/mem, segreg
  573.  
  574.              Notice that you may not (1) move a constant to a segment
  575.              register, (2) move a segment register to another segment
  576.  
  577.  
  578.  
  579.  
  580.              The PC Assembler Tutor                                       xxii
  581.              ______________________
  582.  
  583.              register, or (3) move from memory to memory.
  584.  
  585.  
  586.  
  587.              MOVS moves a byte (or a word) from DS:[si] to ES:[di], and
  588.              increments (or decrements) SI and DI depending on the setting of
  589.              DF, the direction flag (by 1 for bytes and by 2 for words). You
  590.              may use CS:[si], SS:[si] or ES:[si], but you MAY NOT OVERRIDE
  591.              ES:[di].
  592.  
  593.                  movsb
  594.                  movsw
  595.                  movs BYTE PTR ES:[di], SS:[si]     ;or CS, DS, ES:[si]
  596.                  movs WORD PTR ES:[di], SS:[si]     ;or CS, DS, ES:[si]
  597.  
  598.  
  599.  
  600.              MUL performs unsigned integer multiplication. The multiplicand
  601.              must be in AX (or AL for bytes). After the multiplication, the
  602.              result is in DX:AX (or AH:AX for bytes). If DX (or AH for bytes)
  603.              contains significant information, then CF = 1. If all the
  604.              significant information is in AX (or AL for bytes) then CF = 0.
  605.              Multiplication by a constant is not allowed. The MUL instruction
  606.              does not mention AX (or AL). It is understood.
  607.  
  608.                  mul  reg/mem
  609.  
  610.  
  611.  
  612.              NEG performs '0 - number' on a number and sets the flags
  613.              accordingly.
  614.  
  615.                  neg  reg/mem
  616.  
  617.  
  618.  
  619.              NOP (no operation) does absolutely nothing. It can fill up space
  620.              which was previously occupied by a different instruction.
  621.  
  622.  
  623.  
  624.              NOT performs bitwise logical NOT on a word or a byte.
  625.  
  626.                  not  reg/mem
  627.  
  628.  
  629.  
  630.              OR performs bitwise logical OR on a byte or word
  631.  
  632.                  or   reg/mem, reg/mem
  633.                  or   reg/mem, constant
  634.  
  635.  
  636.  
  637.              OUT moves a byte (or word) from AL (or AX) to the named port.
  638.              There are two forms:
  639.  
  640.  
  641.  
  642.  
  643.  
  644.              Appendix II - The 8086 Instruction Set                      xxiii
  645.              ______________________________________
  646.  
  647.                  out  port_number, ax
  648.                  out  dx, ax
  649.  
  650.              where 'port_number' is a CONSTANT which is coded into the machine
  651.              code. The constant may be from 0-255. DX (and it must be DX) may
  652.              hold a port number from 0-65535.
  653.  
  654.  
  655.  
  656.              POP pops a WORD off the stack. Technically, POP takes the word at
  657.              SS:SP and puts it into the named register or memory location,
  658.              then ADDS 2 to SP.
  659.  
  660.                  pop  mem/reg
  661.                  pop  segreg
  662.  
  663.  
  664.  
  665.              POPF pops a WORD off the top of the stack into the flags
  666.              register. Its technical operation is the same as for POP. 
  667.  
  668.  
  669.  
  670.              PUSH pushes a WORD on the stack from the named register or memory
  671.              location. Technically, PUSH subtracts 2 from SP, then moves the
  672.              word to SS:SP.
  673.  
  674.                  push reg/mem
  675.                  push segreg
  676.  
  677.  
  678.  
  679.              PUSHF pushes the flags register on the stack. Its technical
  680.              operation is the same as for PUSH.
  681.  
  682.  
  683.  
  684.              RCR (rotate through carry right) and RCL (rotate through carry
  685.              left) rotate the bits of a register or of memory data right and
  686.              left respectively. The bit which is shoved off the register (or
  687.              data) is placed in CF and CF is placed on the other side of the
  688.              register (or data). There are two fixed forms. (1) rotate 1 bit
  689.              and (2) rotate by the number in CL.
  690.  
  691.                  rcr  reg/mem, 1
  692.                  rcl  reg/mem, cl
  693.  
  694.  
  695.  
  696.              REP. The string instructions may be prefixed by REP/REPE/REPNE
  697.              which will repeat the instructions according to the following
  698.              conditions:
  699.  
  700.                  rep       decrement cx ; repeat if cx is not zero
  701.                  repe      decrement cx ; repeat if cx not zero AND zf = 1
  702.                  repz      decrement cx ; repeat if cx not zero AND zf = 1
  703.                  repne     decrement cx ; repeat if cx not zero AND zf = 0
  704.  
  705.  
  706.  
  707.  
  708.              The PC Assembler Tutor                                       xxiv
  709.              ______________________
  710.  
  711.                  repnz     decrement cx ; repeat if cx not zero AND zf = 0
  712.  
  713.              Here, 'e' stands for equal, 'z' is zero and 'n' is not. These
  714.              repeat instructions should NEVER be used with a segment override,
  715.              since the 8086 will forget the override if a hardware interrupt
  716.              occurs in the middle of the REP loop. 
  717.  
  718.                  rep    movsb
  719.                  repe   scasb
  720.                  repne  cmpsw
  721.  
  722.  
  723.  
  724.              RET returns from the subroutine to the calling program. The
  725.              return will be either NEAR or FAR depending on the type of
  726.              procedure it is in. It may take the parameters off the stack (for
  727.              Pascal) or leave them on the stack (for C).
  728.  
  729.                  ret (6)        ; Pascal - take 6 bytes off the stack
  730.                  ret            ; C - do nothing
  731.  
  732.  
  733.  
  734.              ROR (rotate right) and ROL (rotate left) rotate the bits of a
  735.              register or memory data right and left respectively. The bit
  736.              which is shoved off one end is moved to the other end. CF
  737.              indicates whether the last bit moved from one end to the other
  738.              was a 1 or a 0. There are two fixed forms. (1) rotate 1 bit and
  739.              (2) rotate by the number in CL.
  740.  
  741.                  ror  reg/mem, 1
  742.                  rol  reg/mem, cl
  743.  
  744.  
  745.  
  746.              SAHF (store AH into flags) puts AH into the low byte of the flags
  747.              register.
  748.  
  749.  
  750.  
  751.              SAL (shift arithmetic left) and SHL (shift logical left) are
  752.              exactly the same instruction. They move bits left. 0s are placed
  753.              in the low bit. Bits are shoved off the register or memory data
  754.              on the left side, and CF indicates whether the last bit shoved
  755.              off was a 1 or a 0. It is used for multiplying an unsigned number
  756.              by powers of 2. There are two fixed forms. (1) shift 1 bit and
  757.              (2) shift by the number in CL.
  758.  
  759.                  shl  reg/mem, 1
  760.                  sal  reg/mem, cl
  761.  
  762.  
  763.  
  764.              SAR (shift arithmetic right) shifts bits right. The high (sign)
  765.              bit stays the same throughout the operation. Bits are shoved off
  766.              the register or memory location on the right side. CF indicates
  767.              whether the last bit shoved off was a 1 or a 0. It is used (with
  768.  
  769.  
  770.  
  771.  
  772.              Appendix II - The 8086 Instruction Set                        xxv
  773.              ______________________________________
  774.  
  775.              difficulty) for dividing a signed number by powers of 2. There
  776.              are two fixed forms. (1) shift 1 bit and (2) shift by the number
  777.              in CL.
  778.  
  779.                  sar  reg/mem, 1
  780.                  sar  reg/mem, cl
  781.  
  782.  
  783.  
  784.              SBB (subtract with borrow) subtracts one integer from another and
  785.              then subtracts 1 more if CF is set. It works with both signed and
  786.              unsigned numbers and is used for multiple word arithmetic.
  787.  
  788.                  sbb  reg/mem, reg/mem
  789.                  sbb  reg/mem, constant
  790.  
  791.  
  792.  
  793.              SCAS compares AL (or AX) to the byte (or word) pointed to by
  794.              ES:[di], and increments (or decrements) DI depending on the
  795.              setting of DF, the direction flag (by 1 for bytes and by 2 for
  796.              words).  NO OVERRIDES ARE ALLOWED.
  797.  
  798.                  scasb
  799.                  scasw
  800.                  scas BYTE PTR ES:[di]    ; no override allowed
  801.                  scas WORD PTR ES:[di]    ; no override allowed
  802.  
  803.  
  804.  
  805.              SHR (shift logical right) does the same thing as SHL but in the
  806.              opposite direction. Bits are shifted right. 0s are placed in the
  807.              high bit. Bits are shoved off the register or memory location on
  808.              the right side and CF indicates whether the last bit shoved off
  809.              was a 0 or a 1. It is used for dividing an unsigned number by
  810.              powers of 2. There are two fixed forms. (1) shift 1 bit and (2)
  811.              shift by the number in CL.
  812.  
  813.                  shr  reg/mem, 1
  814.                  shr  reg/mem, cl
  815.  
  816.  
  817.  
  818.              STC sets the carry flag (CF = 1).
  819.  
  820.              STD sets the direction flag (DF = 1, which decrements).
  821.  
  822.              STI sets the interrupt flag (IEF = 1; interrupts enabled).
  823.  
  824.  
  825.  
  826.              STOS (store to string) moves a byte (or a word) from AL (or AX)
  827.              to ES:[di], and increments (or decrements) DI depending on the
  828.              setting of DF, the direction flag (by 1 for bytes and by 2 for
  829.              words). NO SEGMENT OVERRIDES ARE ALLOWED.
  830.  
  831.                  stosb
  832.  
  833.  
  834.  
  835.  
  836.              The PC Assembler Tutor                                       xxvi
  837.              ______________________
  838.  
  839.                  stosw
  840.                  stos BYTE PTR ES:[di]    ; no override allowed
  841.                  stos WORD PTR ES:[di]    ; no override allowed
  842.  
  843.  
  844.  
  845.  
  846.              SUB subtracts one integer from another. It works for both signed
  847.              and unsigned numbers.
  848.  
  849.                  sub  reg/mem, reg/mem
  850.                  sub  reg/mem, constant
  851.  
  852.  
  853.  
  854.              TEST performs logical AND, but does not alter the value of the
  855.              "destination" variable. Its purpose is to set the flags for
  856.              conditional jumps.
  857.  
  858.                  test reg/mem, reg/mem
  859.                  test reg/mem, constant
  860.  
  861.  
  862.  
  863.              WAIT forces the 8086 to wait until the coprocessor is finished
  864.              with its instruction before the 8086 can go on to the next
  865.              instruction.
  866.  
  867.  
  868.  
  869.              XCHG exchanges the values in two registers or memory locations.
  870.  
  871.                  xchg reg/mem, reg/mem
  872.  
  873.  
  874.  
  875.              XLAT. If BX contains the address of a 256 byte translation table,
  876.              then XLAT goes to (BX + AL), takes the byte there and puts it
  877.              into AL. DS is the normal segment, but segment overrides are
  878.              allowed.
  879.  
  880.  
  881.  
  882.              XOR performs logical exclusive OR on two numbers.
  883.  
  884.                  xor  reg/mem, reg/mem
  885.                  xor  reg/mem, constant
  886.  
  887.